package com.ny.mapper;

import com.ny.entity.Device;
import com.ny.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
@Mapper
public interface UserMapper {
    @Insert("insert into user(username,password,nickname,phone,email,is_active,created_time) values(#{username},#{password},#{nickname},#{phone},#{email},#{isActive},#{createdTime})")
    int addUser(User user);

    @Select("select * from user where username = #{username} and password = #{password}")
    public User findIser(@Param("username") String username,@Param("password") String password);
    @Select("select  * from user where email = #{email}")
    public User findUserByEmail(String email);
    @Insert("update user set password = #{password} where email = #{email}")
    public int updatePassword(@Param("password") String password, @Param("email") String email);
    @Select("SELECT * FROM device")
    List<Device> findAllDevices();

    @Select("SELECT * FROM device WHERE device_name LIKE CONCAT('%', #{deviceName}, '%')")
    List<Device> findDevicesByName(String deviceName);
}
